var express = require('express'),
  router = express.Router(),
  path = require('path');
var fs = require('fs'),
  bodyParser = require('body-parser'),
  multiparty = require('multiparty'),
  util = require('util'),
  basic = require('../../basicmodule/basic.js');


module.exports = function (app) {
  app.use('/', router);
};

var utils = require('../tool/Utils.js')

const DIRPATH = 'freedom' + utils.format + 'upload' + utils.format;

var GetFormatData = function (path) {
  let data = basic.getGenFiles(path)
  let jsonFileInfo = JSON.stringify(data.file_info);
  let jsonGenPath = JSON.stringify(data.gen_path);
  return {
    file_info: jsonFileInfo,
    gen_path: jsonGenPath,
    is_root: true,
  }
}

router.get('/showFiles.html', function (req, res, next) {

  let reqPath = req.query.path;
  console.log(reqPath)

  res.render('pages/index', GetFormatData(reqPath))
});

router.get('/lastPage.html', function (req, res, next) {


  let reqPath = req.query.path;
  reqPath = path.resolve(reqPath, '..') + path.sep

  let str = path.relative(reqPath, DIRPATH)
  console.log("hahaha:" + str)

  if(str == ""){
    res.redirect('/index.html');
  }else {
    res.render('pages/index', GetFormatData(reqPath))
  }



});











